<%-- 
    Document   : MBusStation
    Created on : 01/05/2010, 16:28:02
    Author     : TIAGO
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.terminalrodoviario.BusStation"%>
<%@page import="java.util.*, java.text.*"%>
<jsp:useBean class="br.terminalrodoviario.BusStation" id="BusStation" scope="page"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean class="br.terminalrodoviario.User" id="user" scope="session"/>
<%
        if (user.getId() == 0) {
            response.sendRedirect("../login.jsp");
        }
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Guia Terminal Rodoviário</title>
        <style type="text/css">
            @import url("../../add/css/cssAdmin.css");
            @import url("../../add/css/rodape.css");
        </style>
        <script type="text/javascript">
            var cont = 0;
            function buttonValidated(ischecked){
                if(ischecked==true){
                    cont++;
                }else{
                    cont--;
                }
                if(cont!=1)
                    document.getElementById("btnEditar").src = "../../add/images/botoes/btEditarDisable.png";
                else
                    document.getElementById("btnEditar").src = "../../add/images/botoes/btEditar.png";
                if(cont==0)
                    document.getElementById("btnRemover").src = "../../add/images/botoes/btRemoverDisable.png";
                else
                    document.getElementById("btnRemover").src = "../../add/images/botoes/btRemover.png";
                document.getElementById("btnEditar").disabled = cont != 1;
                document.getElementById("btnRemover").disabled = cont == 0;
            }
            function search(){
                location = "MBusStation.jsp?search="+document.getElementById("txtSearch").value;
            }
            function keyPress(event){
                var keyNum;
                if(window.event){
                    keyNum=event.keyCode;
                }else if(event.which){
                    keyNum=event.which;
                }
                if(event.keyCode == 13){
                    search();
                }
            }
        </script>
    </head>
    <body>
        <div class="geral">
            <table>
                <tr>
                    <td>
                        <div id="cabecalho" title="Guia Terminal Rodoviário">
                        </div>
                    </td>
                </tr>
            </table>
            <table id="menuAdmin" width="762">
                <tr >
                    <td align="center">
                        <ul class="menuCidade" >
                            <li><a href="MCity.jsp" title="Cidades"/></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuEmpresa" >
                            <li><a href="MCompany.jsp" title="Empresas"/></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuTerminais" >
                            <li class="current"><a href="MBusStation.jsp" title="Terminais Rodoviários"/></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuHoteis" >
                            <li><a href="MHotel.jsp" title="Hotéis"/></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuNoticias" >
                            <li><a href="MNotice.jsp" title="Notícias"/></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuSolicitacao" >
                            <li><a href="MSolicitation.jsp" title="Solicitações"/></li>
                        </ul>
                    </td>
                    <td>
                        <ul class="menuDicas" >
                            <li><a href="MTravelTip.jsp" title="Dicas de Viagem"/></li>
                        </ul>
                    </td>
                </tr>
            </table>

            <div style="float:left">
                <br/>
                <b><a href="../index.jsp">Início</a> -> <a href="MBusStation.jsp">Terminais Rodoviários</a></b>
                <br/><br/>
            </div>
            <div align="right" style="font-family:calibri; font-size:11px; font-style:inherit">
                <br/>Bem-vindo <b><%=request.getSession().getAttribute("username")%></b>,<br/>
                você está logado desde <%=request.getSession().getAttribute("date_session")%>h. ( <a href="../logout.jsp"><b>Logout</b></a> )<br/><br/>
            </div>

            <table  id="subTitulo">
                <tr>
                    <td id="icone" align="center">
                        &nbsp;&nbsp;&nbsp;<img src="../../add/images/icones/bus_station.png" alt="Terminais Rodoviários" title="Terminais Rodoviários"/>
                    </td>
                    <td>
                        Terminais Rodoviários
                    </td>
                </tr>
            </table>
            <form action="../BusStationServlet" method="post">
                <table id="subMenu">
                    <tr>
                        <td>
                            <ul class="btNovo" >
                                <li><a href="../Fields/FBusStation.jsp" title="Novo"/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btEditar" >
                                <li><input id="btnEditar" type=image src="../../add/images/botoes/btEditarDisable.png" value="Editar" disabled="true" name="edit" title="Editar" alt="Editar"/></li>
                            </ul>
                        </td>
                        <td>
                            <ul class="btRemover" >
                                <li><input id="btnRemover" type=image src="../../add/images/botoes/btRemoverDisable.png" value="Remover" disabled="true" name="delete" title="Remover" alt="Remover"/></li>
                            </ul>
                        </td>
                    </tr>
                </table>

                <div id="conteudo" align="center">
                    <br>
                    <%
                    String search = request.getParameter("search");
                    Collection<BusStation> lst = new BusStation().select("from BusStation n "+ (search != null ? "where n.name like '%"+search+"%'":"")+" order by n.name asc");
                                if (lst != null && lst.size() != 0 && !lst.isEmpty()) {
                    %>
                    <div align="center">
                        <table>
                            <tr>
                                <td class="label_bg" style="width:70px;" align ="center">
                                    <b>Pesquisar:</b>
                                </td>
                                <td>
                                    <input type="text" onkeypress="keyPress(event);" size="35" id="txtSearch" name="txtSearch" value="<%=search!=null?search:""%>"/>
                                </td>
                                <td>
                                    <img src="../../add/images/botoes/search.png" name="Buscar" style="cursor:pointer;" value="Buscar" onclick="javascript:search();" alt="Procurar" title="Procurar"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <br/>
                    <table border="0" width="750" cellspacing="0" cellpadding="0">
                        <tr class="table_header">
                            <th></th>
                            <th align="left">Nome</th>
                            <th align="left">Cidade</th>
                        </tr>
                        <%
                                    Object[] bus_stations = lst.toArray();
                                    int total = bus_stations.length > 15 ? 15 : bus_stations.length;
                                    int i = 0;
                                    int inicio = 0;
                                    int pagina = 1;
                                    if (request.getParameter("page") != null) {
                                        pagina = Integer.parseInt(request.getParameter("page"));
                                    }
                                    if (pagina > 1) {
                                        inicio = total * pagina - total;
                                    }
                                    int fim = total * pagina;
                                    if (fim > bus_stations.length) {
                                        fim = bus_stations.length;
                                    }
                                    if (bus_stations.length > 0) {
                                        for (int j = inicio; j < fim; j++) {
                                            BusStation n = (BusStation) bus_stations[j];
                        %>
                        <tr class="<%=(i % 2 != 0) ? "table_row_bg" : "table_row"%>">
                            <td align="center" width="45"><input type="checkbox" name="id" onchange="buttonValidated(this.checked);" value="<%=n.getId()%>"/></td>
                            <td align="left" width="500" title="<%=n.getName()%>"><%=n.getName()%></td>
                            <td title="<%=n.getCity().getFullName()%>"><%=n.getCity().getFullName()%></td>
                        </tr>
                        <%
                                            i++;
                                        }
                                    }
                        %>
                        <tr>
                            <td colspan="4" align="center">
                                Páginas : <%
                                            int totalPaginas = bus_stations.length / (total == 0 ? 1 : total);
                                            if (bus_stations.length % (total == 0 ? 1 : total) != 0) {
                                                totalPaginas++;
                                            }
                                            for (int j = 1; j <= totalPaginas; j++) {
                                %>
                                <a href="MBusStation.jsp?page=<%=j%>"><%= (j == pagina ? "<b>" : "")%><%=j%><%= (j == pagina ? "</b>" : "")%></a>
                                <%
                                            }
                                %>
                            </td>
                        </tr>
                    </table>
                    <%}else{%>
                        <h3>Não há nenhum registro.</h3>
                    <%}%>
                    <br>
                </div>
            </form>
            <table id="rodape" style="background-image:url(../../add/images/rodape.png);">
                <tr>
                </tr>
            </table>
            <table id="btRodape" style="text-decoration: none;" >
                <tr>
                    <td align="center" width="80px">
                        <ul class="btYoutube">
                            <li><a title="Youtube" href="http://www.youtube.com" /></li>
                        </ul>
                    </td >
                    <td align="center" width="80px">
                        <ul class="btOrkut">
                            <li><a title="Orkut" href="http://www.orkut.com" /></li>
                        </ul>
                    </td>
                    <td align="center" width="205px">
                        <ul class="btTwitter">
                            <li><a title="Twitter" href="http://twitter.com" /></li>
                        </ul>
                    </td>
                    <td align="center">
                        <a title="Trabalhe Conosco" class="text" href="../../Carrer.jsp" >Trabalhe Conosco</a>
                    </td>
                    <td align="center"  width="">
                        <a title="Mapa do Site" class="text" href="../../SiteMap.jsp">Mapa do Site</a>
                    </td>
                    <td align="center" width="">
                        <a title="Contatos" class="text" href="../../Contact.jsp">Contatos</a>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>
